package cn.itlaobing.eshop.web.servlet;

import cn.itlaobing.eshop.entity.SaleDTO;
import cn.itlaobing.eshop.entity.ItlbFocuss;
import cn.itlaobing.eshop.exception.BusinessException;
import cn.itlaobing.eshop.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * @Description:
 * @Author: WangDong
 * @Date: 2017/11/13 15:12
 */
@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        GoodsService goodsService=new GoodsService();
        try {
            List<SaleDTO>list=goodsService.findCounts();

            List<SaleDTO>list2=goodsService.findNew();
            List<ItlbFocuss>list3=goodsService.findPictures();
            req.getSession().setAttribute("LIST",list);
            req.getSession().setAttribute("LIST2",list2);
            //System.out.println(">>>>>>>>>>>>>>>>>>>>home"+list.size());
            req.setAttribute("Pictures",list3);
        } catch (BusinessException e) {
            e.printStackTrace();
        }


        req.getRequestDispatcher("/WEB-INF/views/index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
